<?php require VIEWPATH . ADMIN_DIR . DIRECTORY_SEPARATOR . 'sub' . DIRECTORY_SEPARATOR .'header.php'?>
<style>
    .cate-type {
        color: #438EB9;
        border: 1px solid #438EB9;
        padding: 1px 3px;
    }
    .recommend {
        color: #FE9B01;
        border: 1px solid #FE9B01;
        padding: 1px 20px;
    }
    .outer-table {
        margin: 20px 200px;
    }
    .clearfix {
        padding: 30px;
        text-align: center;
    }
    .btn-save {
        width:110px;
        height:40px;
        color: #FFF;
        background:#438EB9;
        border-radius:4px;
        font-size:16px;
        border: none !important;
        margin-right: 100px;
    }
    a.back {
        margin-right: 40px;
        color: #438EB9;
        font-size: 16px;
        display: flex;
        align-items: center;
    }
    a.back i {
        font-size: 25px;
    }
    .ant-card-head-title {
        text-align: center;
        margin-right: 15%;
    }
</style>
<div class="ant-card page-wrap com-card static-page___2-4kT">
    <div class="ant-card-head">
        <div class="ant-card-head-wrapper">
            <div><a class="back" href="<?= admin_url('sub/cms/index') ?>"><i class="fa fa-angle-left"></i>&nbsp;&nbsp;返回</a></div>
            <div class="ant-card-head-title">发布文章</div>
        </div>
    </div>
    <div class="outer-table">
		<form class="form-horizontal" id="article-form">
			<input type="hidden" name="id" value="<?=$articleInfo['id']?>" />
			<input type="hidden" name="article_cover" value="<?=$articleInfo['article_cover']?>" />
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章标题</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="article_title" placeholder="请填写文章标题" value="<?=$articleInfo['article_title']?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章封面</label>
				<div class="col-sm-6" style="margin-top: 10px;">
					<a href="javascript:;" id="upload-img">
						<?php if($articleInfo['article_cover']): ?>
							<img class="fit-cover" src="<?=$articleInfo['article_cover']?>" width="160" height="196" />
						<?php else: ?>
							<img class="fit-cover" src="<?=$staticAdminUrl?>sub/assets/img/cms/add.png" width="160" height="196" />
						<?php endif;?>
					</a>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章分类</label>
				<div class="col-sm-6">
					<select class="form-control" name="category_id">
						<?php foreach($categoryList as $category): ?>
							<option value="<?=$category['id']?>">
								<?=$category['parent_id'] ? "&nbsp;∟ " : ""?><?=$category['category_name']?>
							</option>
						<?php endforeach; ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章内容</label>
				<div class="col-sm-6">
					<textarea class="pd0" id="content" name="article_content" style="height: 400px;width: 100%"><?=urldecode($articleInfo['article_content'])?></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">文章排序</label>
				<div class="col-sm-6">
					<input class="form-control" type="number" name="article_sort" placeholder="请填写文章排序" value="<?=$articleInfo['article_sort']?>" />
				</div>
			</div>
			<div class="clearfix">
				<div class="">
					<button class="btn-save" type="button">
						提交
					</button>
				</div>
			</div>
		</form>
    </div>
</div>
<?php require VIEWPATH . ADMIN_DIR . DIRECTORY_SEPARATOR . 'sub' . DIRECTORY_SEPARATOR .'footer.php'?>
<!-- 百度编辑器 -->
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.config.js"></script>
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.all.js"></script>
<script>
	var ue;

    $(function(){
        // 切换栏目类型
        $("[name=category_type]").change(function(){

            var categoryType = $(this).val();
            if(categoryType == <?=CMS_CATEGORY_ARTICLE?>) {
                show_article_type();
            } else {
                $("#category-article-div").addClass("hide");
            }
        })

        // 初始化编辑器
		ue = UE.getEditor('content');
		var uploadTarget = $("#upload-img");
		// 初始化头像上传插件
		setTimeout(function(){
			uploadTarget.uploader({
				"server":  '<?=UP_FORM_URL?>',
				"authorization": "<?=$signature?>",
				"policy": "<?=$policy?>",
				"callback": function(response) {
					var imgFile = "<?=UP_URL?>" + response.url;
					uploadTarget.find("img").attr("src", imgFile);
					form.find("[name=article_cover]").val(imgFile);
				}
			});
		}, 200);
        // 提交表单
        var form = $("#article-form");
        var submitUrl = "<?=admin_url('cms/save_article_action')?>";


        // 点击提交按钮
        $(".btn-save").click(function(){
			// alert(1);
            $("[name=category_article_content]").val(ue.getContent());
            form.submit();
        })
        // 提交表单
        form_submit(form, submitUrl, function(res) {
            tips_alert(res.msg, res.success, function(){
                if(res.success) window.location.href = "<?=admin_url('sub/cms/index')?>"
            });
        })
    })
</script>